package com.wangjw.leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by wangjw on 18/6/20.
 */
public class LeetCode804 {

    public int uniqueMorseRepresentations(String[] words) {
        String[] codes = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};

        Set<String> set = new HashSet<>();
        for (String word : words) {
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < word.length(); i++) {
                builder.append(codes[word.charAt(i) - 'a']);
            }
            set.add(builder.toString());
        }

        return set.size();
    }

    public static void main(String[] args) {
        LeetCode804 leetCode804 = new LeetCode804();
        String[] words = {"gin", "zen", "gig", "msg"};
        int result = leetCode804.uniqueMorseRepresentations(words);
        System.out.println(result);
    }
}
